<?php
/**
 * Created by PhpStorm.
 * User: nathan
 * Date: 2019/2/13
 * Time: 11:26
 */

use Monolog\Handler\StreamHandler;
use Monolog\Logger;

return [
    'app.dir' => dirname(__DIR__),
    'iplookup.service' => function ($c) {
        return new \Refine\Service\IplookupService(['iplookup' => $c['iplookup'], 'cache' => $c['cachewithlog.service'], 'logger' => $c['logger']]);
    },
    'curl' => function ($c) {
        $curl = new \Curl\Curl();
        $curl->setUserAgent('Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36');
//        $curl->setOpt([CURLOPT_FOLLOWLOCATION => 1]);
        return $curl;
    },
    'iplookup' => function ($c) {
        return new \Refine\Iplookup\PconlineIplookup($c['curl']);
    },
    'cache' => function ($c) {
//        return new \Symfony\Component\Cache\Simple\NullCache();
        return new \Symfony\Component\Cache\Simple\FilesystemCache('',1 * 24 * 60 * 60, dirname(__DIR__) .'/runtime/log');
    },
    'cachewithlog.service' => function($c){
      return  new \Refine\Service\CacheWithLogService(['cache'=>$c['cache'],'logger'=>$c['logger']]);
    },
    'logger' => function ($c) {
        $logger = new Logger('development');
        $logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
        return $logger;
    }
];